<?php
namespace app\home\controller;
use think\Controller;
use think\Db;

class Index extends Controller
{
	//显示首页
    public function index()
    {
        //显示首页


     //轮播图显示
        $res= \think\Db::view('slideshow','shop_id,up,createtime,picture')
        ->view('dining','shopname','slideshow.shop_id = dining.shop_id')
            ->order('createtime desc')
            ->select();
        $this->assign('slideshowres',$res);
        //新进餐厅显示
        $newshop = \think\Db::name('dining')->order('createtime desc')
        ->where('state',1)
        ->paginate(3);
        $this->assign('newsshops',$newshop);
     /*新进菜品显示*/
        $newsfood =\think\Db::name('food')->order('addate desc')->paginate(3);
        $this->assign('newsfoods',$newsfood);
        $offer = \think\Db::name('food')->order('startdate desc')->paginate(3);
        $this->assign('specialoffer',$offer);
         /*
        根据店铺的销量和对热门餐厅进行排序
        */
        $hotshop = \think\Db::name('dining')
        ->alias('a')
        ->join('__ORDER__ b','a.shop_id=b.shop_id')
        ->field('a.shop_id,shopname,pic,level,fei,obserave,sum(b.num)')
        ->group('a.shop_id')
        ->order('sum(b.num) desc')
        ->paginate(4);
    $this->assign('hotshop', $hotshop);
    $hotfood = \think\Db::name('food')
    ->alias('a')
    ->join('__ORDER__ b','a.food_id=b.food_id')
    ->join('__DINING__ c','a.shop_id=c.shop_id')
    ->field('a.shop_id,foodname,a.pic,price,obserave,sum')
    ->order('sum desc')
    ->paginate(6);
    // dump($hotfood);
    // die();
    $this->assign('hotfood',$hotfood);

        return $this->fetch();
    }
    //显示查询结果
    public function searchlists()
    {
        $searc = input('Search');
        $map['shopname'] = array('like','%'.$searc.'%');
        $searclists = \think\Db::name('dining')->where($map)->paginate(6);
        $this->assign('searchlists',$searclists);
        

       

        return $this->fetch();
    }


}
